package net.mcreator.toolsasfood.procedures;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.event.entity.player.UseHoeEvent;

import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.effect.MobEffectInstance;

import net.mcreator.toolsasfood.init.ToolsAsFoodModMobEffects;

import javax.annotation.Nullable;

@Mod.EventBusSubscriber
public class IronHoeusedProcedure {
	@SubscribeEvent
	public static void onUseHoe(UseHoeEvent event) {
		Player entity = event.getPlayer();
		execute(event, entity);
	}

	public static void execute(Entity entity) {
		execute(null, entity);
	}

	private static void execute(@Nullable Event event, Entity entity) {
		if (entity == null)
			return;
		if (entity instanceof LivingEntity _livEnt ? _livEnt.hasEffect(ToolsAsFoodModMobEffects.IRON_HOE_JUMP) : false) {
			if (entity instanceof LivingEntity _livEnt ? _livEnt.hasEffect(MobEffects.JUMP) : false) {
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.JUMP,
							entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(MobEffects.JUMP)
									? _livEnt.getEffect(MobEffects.JUMP).getDuration()
									: 0,
							(int) ((entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(MobEffects.JUMP)
									? _livEnt.getEffect(MobEffects.JUMP).getAmplifier()
									: 0) + 1)));
			} else {
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.JUMP, 1200, 0));
			}
		}
	}
}
